<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class m_login extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function check_user($userinfo = array()) {
        $error = 0;
        $msg = '';

        $this->load->database();
        $sql = 'SELECT * FROM `com_admin`  WHERE admin_name = "' . $userinfo['admin_name'] . '"';
        $user = $this->db->query($sql)->row_array();

        if (!$user) {
            $msg = "用户名不存在";
            $error = 1;
        }elseif($user['enable'] != 1) {
            $msg = "你的账号已冻结";
            $error = 1;
        }else {
            $this->load->library('PwdEncryption'); //导入加密文件
            $p = new PwdEncryption();
          //  echo $p->getEncryptPwd($userinfo['admin_pwd'], $user['admin_salt']);
            if ($p->getEncryptPwd($userinfo['admin_pwd'], $user['admin_salt']) != $user['admin_pwd']) {
                $msg = "密码错误";
                $error = 1;
            }
        }
        
        $result['error'] = $error;
        $result['msg'] = $msg;
        $result['user'] = $user;
        return $result;
    }

}

?>